package com.woniuxy.reader.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniuxy.reader.entity.Author;
import com.woniuxy.reader.entity.Book;
import com.woniuxy.reader.vo.AuthorVO;
import com.woniuxy.reader.vo.BookVO;
import com.woniuxy.reader.vo.BookVOO;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zh_o
 * @since 2020-10-09
 */
public interface AuthorMapper extends BaseMapper<Author> {

    /**
     * 作者列表
     * 作者、书籍联表
     *
     * @param page
     * @param queryWrapper
     * @param vo
     * @return
     */
    IPage<Author> listAuthorByBook(IPage<Author> page, QueryWrapper<Author> queryWrapper, AuthorVO vo);

    @Select("select a.author_id,a.pen_name,sum(b.count) sumbooknum,count(b.book_id) countbook,a.author_tel,a.qq,a.author_time,sum(bd.click_number) clicknum from author a LEFT JOIN book b on b.author_id=a.author_id LEFT JOIN book_data bd ON b.book_id=bd.book_id where level='申请签约' GROUP BY a.author_id")
    List<BookVOO> selectByEditorTel();

    /**
     * 根据传入的作者id查询作品总字数以及总作品数
     * @param authorid
     * @return
     */
    @Select("select sum(b.count) sumBookNum,count(book_id) countBook from book b where b.author_id=#{authorid}")
    BookVO selectSginAuthorDetail(int authorid);

    @Update("update author set level='签约写手',editor_id=#{editorid} where author_id=#{authorid}")
    void SginAuthor(int authorid,int editorid);

}
